#pragma once

#include<string>
#include<vector>

#include"db_connection.h"
#include"db_row.h"

namespace uhdpbs {
	namespace db {
		class connection;
		class row;

		typedef std::vector<std::string> string_vector;
		typedef string_vector::iterator string_iterator;
		typedef std::vector<row> row_vector;
		typedef row_vector::iterator row_iterator;
		typedef std::map<std::string, enum_field_types> string_fieldtype_map;
		typedef string_fieldtype_map::iterator string_fieldtype_iterator;
		typedef std::map<std::string, std::string> string_string_map;
		typedef string_string_map::iterator string_string_iterator;

		class table {
		protected:
			connection* pdbConnection;

			row_vector vRows;

			string_vector vColumns;
			string_string_map mLabels;
			string_fieldtype_map mTypes;

		public:
			/*
			Initializes the table and identifies the connection to use.
			conn: The database connection to use.
			*/
			table(connection* conn);
			~table();

			/*
			The provides classes generated from the database a location to record the SQL table name.
			Returns: SQL table name.
			*/
			virtual std::string get_name() =0;

			/**
			Provides a list of SQL column names.  This is used by the connection for loading and saving data.
			Returns: vector of SQL column names.
			*/
			string_vector* get_columns();
			/**
			<summery>For each column, and at the same vector index, this provides the user friendly display name for each column.  These names are generated through the "connection.get_user_freidnly_name()". </summery>
			<returns>Returns vector of SQL column names.</returns>
			*/
			string_string_map* get_labels();
			string_fieldtype_map* get_types();
			connection* get_connection();

			unsigned long save();
			unsigned long load(std::string order = "");
			void clear();

			row create_new_row();
			virtual row create_new_row(uhdpbs::db::string_string_map originals) =0;

			row_vector* get_rows();
		};
	}
}